﻿using PersonaLibrary.Data;

namespace PersonaLibrary.ViewModel
{
    public class LinqEditableItem<TEntity, TView> : EditableItemViewModel<TEntity, TView>
        where TEntity : BaseEntity
        where TView : View.IView, new()
    {
        protected LinqToDbDataContext Context = new LinqToDbDataContext();
		
        public override void Commit()
        {
            if(EditableItem != null && EditableItem.Id == 0) 
				Context.GetTable<TEntity>().InsertOnSubmit(EditableItem);
            Context.SubmitChanges();
            base.Commit();
        }

        public override void Dispose()
        {
            Context.Dispose();
        }
    }
}
